package com.qys.livesMall.event.listener;

import com.qys.livesMall.app.user.event.LoginEvent;
import com.qys.livesMall.app.user.model.dto.sys.LoginInfoDTO;
import com.qys.livesMall.app.user.service.UserShopStatisticsService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;

@RequiredArgsConstructor
public class LoginListener {

    private final UserShopStatisticsService userShopStatisticsService;
    @Async
    @Order
    @EventListener(LoginEvent.class)
    public void saveUserStatisticsInfo(LoginEvent loginEvent){
        LoginInfoDTO loginInfoDTO = (LoginInfoDTO) loginEvent.getSource();
        userShopStatisticsService.updateUserIP(loginInfoDTO);
    }
}
